package com.java.comprehensive.arithmetic.leecode.easy;

public class LeetCode_1047 {

    public static String removeDuplicates(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (sb.length() <= 0 || sb.charAt(sb.length() - 1) != c) {
                sb.append(c);
            } else {
                sb.deleteCharAt(sb.length() - 1);
            }
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) {
        String ca = "abbaca";
        System.out.println(removeDuplicates(ca));
    }
}
